package models

import "github.com/jinzhu/gorm"

type User struct {
	gorm.Model
	Name   string `gorm:"unique_index"`
	Phone  string `gorm:"unique_index"`
	Pwd    string
	Avatar string
	Role   int
}

//通过用户名和密码查询用户
func QueryUserByUnameAndPwd(phone string, pwd string) (user User, err error) {
	return user, db.Where("phone = ? and pwd = ?", phone, pwd).Take(&user).Error
}

//通过手机号查询用户是否已存在
func QueryUserByPhone(phone string) (user User, err error) {
	return user, db.Where("phone = ? ", phone).Take(&user).Error
}

//保存注册新用户
func SaveUser(user *User) error {
	return db.Save(user).Error
}
